package com.mo.ld.activity.interactive.behavior

import android.os.Bundle
import android.view.View
import android.widget.HorizontalScrollView
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.dylanc.longan.activity
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
import com.mo.ld.R
import com.mo.ld.databinding.ActBehaviorBottomsheetBinding
import com.mo.lib.ui.activity.BaseVbActivity
import com.mo.lib.utils.getView
import com.mo.lib.utils.setClick
import com.mo.lib.utils.showToast
import com.mo.lib.utils.view.getBottomSheetBehavior
import com.mo.lib.view.recyclerview.KRecyclerView
import com.mo.lib.view.recyclerview.layoutG

/**
 * @ author：mo
 * @ data：2022/4/6:16:31
 * @ 功能：联动BottomSheetBehavior
 */
class BottomSheetBehaviorActivity : BaseVbActivity<ActBehaviorBottomsheetBinding>() {
    val mutableListOf = mutableListOf("1", "2", "3", "4", "5", "6", "7", "2", "3", "4", "5", "6", "7", "2", "3", "4", "5", "6", "7", "2", "3", "4", "5", "6", "7", "2", "3", "4", "5", "6", "7")
    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        viewBinding.llBottomSheet.getBottomSheetBehavior()?.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
            override fun onStateChanged(bottomSheet: View, newState: Int) {
                when (newState) {
                    STATE_EXPANDED -> { //展开
                        showToast("展开")
                    }
                    STATE_COLLAPSED -> { //折叠状态，显示peekHeigth 的高度，如果peekHeight为0，则全部隐藏,与STATE_HIDDEN效果一样。
                        showToast("折叠")
                    }
                }
            }

            override fun onSlide(bottomSheet: View, slideOffset: Float) {


            }
        })
        viewBinding.tvBehavior1.setClick {//加tv
            viewBinding.llBehavior.removeAllViews()
            for ((indext, item) in mutableListOf.withIndex()) {
                val view = getView(R.layout.item_main)
                view.setClick {
                    showToast("dddddddd${(this.findViewById<TextView>(R.id.tv_item_main)).text}")
                }
                view.findViewById<TextView>(R.id.tv_item_main).text = "tv:${item}"
                viewBinding.llBehavior.addView(view)
            }
        }
        viewBinding.tvBehavior2.setClick {//加rv
            viewBinding.llBehavior.removeAllViews()
            val kRecyclerView = KRecyclerView(context)
            kRecyclerView.layoutG(5).adapter = object : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_main, mutableListOf) {
                override fun convert(holder: BaseViewHolder, item: String) {
                    holder.getView<TextView>(R.id.tv_item_main).text = "rv:${item}  "
                    holder.itemView.setClick {
                        showToast("gansha")
                    }
                }
            }
            viewBinding.llBehavior.addView(kRecyclerView)
        }
        viewBinding.tvBehavior3.setClick {//加hsv
            viewBinding.llBehavior.removeAllViews()
            val hsv=HorizontalScrollView(activity)
            val ll=LinearLayout(activity)
            ll.orientation=LinearLayout.HORIZONTAL
            for ((indext, item) in mutableListOf.withIndex()) {
                val view = getView(R.layout.item_main)
                view.findViewById<TextView>(R.id.tv_item_main).text = "hsv:${item}  "
                ll.addView(view)
            }
            hsv.addView(ll)
            viewBinding.llBehavior.addView(hsv)

        }
        viewBinding.krvBehavior.setMaxHeight(150).adapter = object : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_main, mutableListOf) {
            override fun convert(holder: BaseViewHolder, item: String) {
                holder.getView<TextView>(R.id.tv_item_main).text = item
                holder.itemView.setClick {
                    showToast("gansha")
                }
            }
        }
    }

    override fun initData() {
    }

}